using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class UI_ItemSlot_Equipment: UI_ItemSlot
{ 

    [SerializeField] private Sprite defaultSprite;
    protected ItemData_Equipment itemEquipment;
    public EquipmentType equipmentType;

    public void Start()
    {
        itemImage.sprite = defaultSprite;
    }

    private void OnValidate()
    {
        gameObject.name = equipmentType.ToString();
    }

    public override void UpdateSlot(InventoryItem item)
    {
        if (item != null)
        {
            this.item = item;
            this.itemEquipment = item.data as ItemData_Equipment;
            itemImage.sprite = item.data.icon;
            itemImage.color = Color.white;
        }
        else
        {
            this.item = null;
            this.itemEquipment = null;
            itemImage.sprite = defaultSprite;
        }
    }

    public override void OnPointerDown(PointerEventData eventData)
    {
        if (this.itemEquipment != null)
        {
            if (eventData.pointerId == -2)
            {
                InventoryManager.instance.UnEquip(this.itemEquipment.equimentType);
            } else if (eventData.pointerId == -1) 
            {
                InventoryManager.instance.UseItem(item);
            }
        }
    }

}
